package com.loan.controller.sms;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.common.enums.SmsTemplateType;
import com.loan.system.domain.SmsConfigEntity;
import com.loan.system.domain.SmsTemplateEntity;
import com.loan.system.service.PayBankService;
import com.loan.system.service.SmsTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiguang on 2022/9/15 15:44
 */
@Validated
@Api(value = "短信模板配置", tags = {"短信模板配置"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/sms/template")
public class SmsTemplateController extends BaseController {

    private final SmsTemplateService smsTemplateService;

    /**
     * 获取短信模板配置列表
     */
    @ApiOperation("获取短信模板配置列表")
    //@SaCheckPermissio("app:smsTemplate:list")
    @GetMapping("/page")
    public TableDataInfo<SmsTemplateEntity> list(SmsTemplateEntity entity, PageQuery pageQuery) {
        return smsTemplateService.selectPageList(entity, pageQuery);
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    //@SaCheckPermissio("app:smsTemplate:query")
    @GetMapping(value = "/{id}")
    public Result<SmsTemplateEntity> getInfo(@ApiParam("ID") @PathVariable Long id) {
        return Result.ok(smsTemplateService.selectSmsTemplateById(id));
    }

    /**
     * 新增模板
     */
    @ApiOperation("新增模板")
    //@SaCheckPermissio("app:smsTemplate:add")
    @Log(title = "新增模板", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody SmsTemplateEntity entity) {
        return toAjax(smsTemplateService.insertSmsTemplate(entity));
    }

    /**
     * 修改模板
     */
    @ApiOperation("修改模板")
    //@SaCheckPermissio("app:smsTemplate:update")
    @Log(title = "修改模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody SmsTemplateEntity entity) {
        return toAjax(smsTemplateService.updateSmsTemplate(entity));
    }

    /**
     * 删除模板
     */
    @ApiOperation("删除模板")
    //@SaCheckPermissio("app:smsTemplate:remove")
    @Log(title = "删除模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(smsTemplateService.deleteSmsTemplateById(id));
    }

    /**
     * 状态修改
     */
    @ApiOperation("状态修改")
    //@SaCheckPermissio("app:smsTemplate:update")
    @Log(title = "状态修改", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public Result<Void> changeStatus(@RequestBody SmsTemplateEntity entity) {
        return toAjax(smsTemplateService.updateSmsTemplateStatus(entity));
    }

    @ApiOperation("获取短信模板类型列表")
    //@SaCheckPermissio("app:smsTemplate:query")
    @GetMapping(value = "/getTypeList")
    public Result<List> getTypeList(){
        return Result.ok(SmsTemplateType.getList());
    }
}
